package com.srwl.mytx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.srwl.mytx.Constant;
import com.srwl.mytx.domain.Coupon;
import com.srwl.mytx.fragment.SendSinglePacketFragment;
import com.srwl.mytx.widget.RPTitleBar;
import com.srwl.mytx.R;


public class SendSingleCouponActivity extends BaseActivity {


    private RPTitleBar mTitleBar;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_send_single_coupon);
        initViewsAndEvents();
    }

    //必须重写，不然状态栏字体是黑色，，
    protected void setStatusDark(){
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.rp_top_red_color));
    }

    protected void initViewsAndEvents() {

        String targetId = getIntent().getStringExtra("targetId");
        int redPacketType = getIntent().getIntExtra("redPacketType", 0);

        if (redPacketType == Constant.COUPON_TYPE_SINGLE) {
            SendSinglePacketFragment sendSinglePacketFragment = SendSinglePacketFragment.newInstance(targetId);
            getSupportFragmentManager().beginTransaction().add(R.id.money_fragment_container, sendSinglePacketFragment).commit();
            sendSinglePacketFragment.setInteractionListener(getInteractionListener());
        }

        mTitleBar = findViewById(R.id.title_bar);
        mTitleBar.setLeftLayoutClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hideSoftKeyboard();
                finish();
            }
        });

        setSubTitle(mTitleBar);
        mTitleBar.setRightImageLayoutVisibility(View.GONE);

    }

    private SendSinglePacketFragment.OnFragmentInteractionListener getInteractionListener() {

        return new SendSinglePacketFragment.OnFragmentInteractionListener() {
            @Override
            public void onPayFundCouponSuccess(Coupon coupon) {

                setResult(RESULT_OK, new Intent().putExtra("coupon", coupon));
                finish();
            }

            @Override
            public void showToast(String message) {

            }
        };


    }

    private void setSubTitle(RPTitleBar titleBar) {
        if (titleBar == null) {
            return;
        }

        titleBar.setSubTitleVisibility(View.GONE);
        titleBar.setSubTitleVisibility(View.VISIBLE);


    }

}
